package us.icitap.cm.business.entities;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.eclipse.persistence.annotations.Customizer;

import us.icitap.cm.utils.MyCustomizer;

@Entity
@Customizer(MyCustomizer.class)
@Table(name="EXPERTISE",schema="MPC")
public class Expertise implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = -7650757012646496009L;

	
	public enum ExpConclusionEnum{
		POSITIV("POZITIV"),
		POSSIBLE("I MUNDSHEM"),
		NEGATIV("NEGATIV");
		
		private String caption;
		private ExpConclusionEnum(String caption){
			this.caption = caption;
		}
		
		public String getCaption(){
			return this.caption;
		}
		
		public String toString(){
			return this.caption;
		}
	}
	
	@Id
	@Column(insertable=false, updatable = false)
	private Integer id;
	
	
	@OneToOne
	@JoinColumn(name="ID",nullable=false)
	private AppEntity appEntity;
	
	@Temporal(TemporalType.DATE)
	@Column(name="EXPERTISE_DATE")
	private Date expertiseDate;
	
	@Column(name="EXP_ACT_NO", length=10)
	private String expertiseActNo;
	
	@ManyToOne
	@JoinColumn(name="EXPERTISE_TYPE_ID")
	private AppList expertiseType;
	
	@Enumerated(EnumType.STRING)
	@Column(name="EXP_CONCLUSION")
	private ExpConclusionEnum expertiseConclusion;
	
	public Expertise(){
		
	}
	
	public Expertise(Expertise expertise){
		this.expertiseDate = expertise.getExpertiseDate();
		this.expertiseActNo = expertise.getExpertiseActNo();
		this.expertiseType = expertise.getExpertiseType();
		this.expertiseConclusion = expertise.getExpertiseConclusion();
		
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public AppEntity getAppEntity() {
		return appEntity;
	}

	public void setAppEntity(AppEntity appEntity) {
		this.appEntity = appEntity;
	}

	public Date getExpertiseDate() {
		return expertiseDate;
	}

	public void setExpertiseDate(Date expertiseDate) {
		this.expertiseDate = expertiseDate;
	}

	public String getExpertiseActNo() {
		return expertiseActNo;
	}

	public void setExpertiseActNo(String expertiseActNo) {
		this.expertiseActNo = expertiseActNo;
	}

	public AppList getExpertiseType() {
		return expertiseType;
	}

	public void setExpertiseType(AppList expertiseType) {
		this.expertiseType = expertiseType;
	}

	public ExpConclusionEnum getExpertiseConclusion() {
		return expertiseConclusion;
	}

	public void setExpertiseConclusion(ExpConclusionEnum expertiseConclusion) {
		this.expertiseConclusion = expertiseConclusion;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		
		result = prime * result
				+ ((expertiseActNo == null) ? 0 : expertiseActNo.hashCode());
		result = prime
				* result
				+ ((expertiseConclusion == null) ? 0 : expertiseConclusion
						.hashCode());
		result = prime * result
				+ ((expertiseDate == null) ? 0 : expertiseDate.hashCode());
		result = prime * result
				+ ((expertiseType == null) ? 0 : expertiseType.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Expertise other = (Expertise) obj;
		
		if (expertiseActNo == null) {
			if (other.expertiseActNo != null)
				return false;
		} else if (!expertiseActNo.equals(other.expertiseActNo))
			return false;
		if (expertiseConclusion != other.expertiseConclusion)
			return false;
		if (expertiseDate == null) {
			if (other.expertiseDate != null)
				return false;
		} else if (!expertiseDate.equals(other.expertiseDate))
			return false;
		if (expertiseType == null) {
			if (other.expertiseType != null)
				return false;
		} else if (!expertiseType.equals(other.expertiseType))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}
	
	
	public boolean myEquals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Expertise other = (Expertise) obj;
		
		if (expertiseActNo == null) {
			if (other.expertiseActNo != null)
				return false;
		} else if (!expertiseActNo.equals(other.expertiseActNo))
			return false;
		if (expertiseConclusion != other.expertiseConclusion)
			return false;
		if (expertiseDate == null) {
			if (other.expertiseDate != null)
				return false;
		} else if (!expertiseDate.equals(other.expertiseDate))
			return false;
		if (expertiseType == null) {
			if (other.expertiseType != null)
				return false;
		} else if (!expertiseType.equals(other.expertiseType))
			return false;
		
		return true;
	}
	
	@Override
	public String toString() {
		return "Akt Ekspertize nr. " + this.getExpertiseActNo();
	}
	
}
